-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(baseapp): fix BaseApp.getContext data races #18383
Conversation
WalkthroughThe changes primarily focus on improving the Cosmos SDK by addressing a data race issue in Changes
Assessment against linked issues (Beta)
Poem
TipsChat with CodeRabbit Bot (
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Commits
Files that changed from the base of the PR and between fb9dadc and 4bc26ca4061b2d5b7344e1469f7d7ea5e55b5265.Files selected for processing (1)
- baseapp/baseapp.go (3 hunks)
Additional comments: 3
baseapp/baseapp.go (3)
9-9: The
sync
package is imported to use thesync.Mutex
type for concurrency control.63-63: A new
sync.Mutex
field,mu
, is added to theBaseApp
struct to protect certain fields during concurrent access.646-648: The
getContextForTx
function now acquires the mutexmu
at the start and ensures it is released when the function exits. This makes the function's operations atomic, preventing data races.
4bc26ca
to
af66258
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Commits
Files that changed from the base of the PR and between fb9dadc and af66258a25f5bbb5686e6a7ad9adeb7732b6260d.Files selected for processing (2)
- CHANGELOG.md (1 hunks)
- baseapp/baseapp.go (3 hunks)
Additional comments: 4
CHANGELOG.md (1)
- 75-78: The changes in the changelog accurately reflect the updates made in the pull request. Ensure that the links to the pull requests are correct and lead to the appropriate changes.
baseapp/baseapp.go (3)
6-12: The
sync
package is imported to usesync.Mutex
for thread safety.62-66: A new mutex
mu
is added to theBaseApp
struct to protect certain fields during concurrent access.643-651: The
getContextForTx
function now uses themu
mutex to ensure thread safety during concurrent access. The mutex is locked at the start of the function and deferred to unlock at the end, ensuring it will be unlocked even if the function exits early.app.mu.Lock() defer app.mu.Unlock()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a failing test. I think mutexes should be operated through pointers receivers to ensure synchronized behavior
This change adds a mutex to BaseApp and firstly locks it when invoking (*BaseApp).getContextForTx. Ideally the (types/sdk).Context should be concurrency safe mirroring the Go standard library's context.Context. Fixes #18382
af66258
to
95f365e
Compare
Thanks @likhita-809 for the feedback, please take a look! Sadly a consequence of our coding style of not sticking to pointer receivers is such test failures. I've modified BaseApp.ExecuteGenesisTx to be a pointer receiver. Tnank you @tac0turtle for the review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- CHANGELOG.md (1 hunks)
- baseapp/baseapp.go (3 hunks)
- baseapp/genesis.go (1 hunks)
Additional comments: 5
CHANGELOG.md (1)
- 75-78: The changes in the changelog are well-documented and provide clear information about the bug fixes and improvements made in the Cosmos SDK. The links to the pull requests provide a good reference for further details.
baseapp/genesis.go (1)
- 12-18: The change from
BaseApp
to*BaseApp
as the receiver ofExecuteGenesisTx
is appropriate as it allows the method to modify the state of theBaseApp
instance. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.baseapp/baseapp.go (3)
9-9: The
sync
package is imported to usesync.Mutex
for thread safety.63-63: A
sync.Mutex
namedmu
is added to theBaseApp
struct to protect certain fields during concurrent access.646-648: The
getContextForTx
function now acquires and releases the mutex to ensure safe concurrent access to certain fields.+ app.mu.Lock() + defer app.mu.Unlock()
This change adds a mutex to BaseApp and firstly locks it when invoking (*BaseApp).getContextForTx. Ideally the (types/sdk).Context should be concurrency safe mirroring the Go standard library's context.Context.
Fixes #18382
Summary by CodeRabbit
ExecuteGenesisTx
method to a pointer receiver for better state management.